package learn.netty.udp;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.channel.*;
import org.jboss.netty.channel.socket.DatagramChannelFactory;
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;

public class UDPGet {

	private ConnectionlessBootstrap udpBootstrap;
	public UDPGet(int port){
		 DatagramChannelFactory channelFactory = new NioDatagramChannelFactory();
         udpBootstrap = new ConnectionlessBootstrap(channelFactory);
         udpBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
             @Override
             public ChannelPipeline getPipeline() throws Exception {
                 return Channels.pipeline(new UdpEventHandler());
             }
         });
         udpBootstrap.bind(new InetSocketAddress("59.66.136.193", port));
         System.out.println("udp server started, listening on port:" + port);
        /* try {
			System.out.println(InetAddress.getLocalHost().getHostAddress());
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new UDPGet(5678);
	}

}
